<html lang="zh-CN">

<head>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>云盘</title>
	<link rel="stylesheet" href="js/filedisk.css" type="text/css">
	<style type="text/css">
		<!--
		.STYLE1 {
			color: #FFFFFF;
			font-weight: bold;
		}
		-->
		label {
		position:
		relative;
		}
		#userimg {
		position:
		absolute;
		left:
		-7px;
		top:
		4px;
		opacity:
		0;
		height:
		36px;
		width:
		116px;
		}
		#userbtn {
		font-size:
		16px;
		padding:
		1px
		1px;
		background:
		none;
		color:
		#0055ff;
		border:
		none;
		width:
		100px;
		}
		progress
		{
		height:
		10px;
		width:
		200px;
		background-color:
		#ddd;
		}
		.edit-window
		{
		display:
		none;
		position:
		fixed;
		top:
		50%;
		left:
		50%;
		transform:
		translate(-50%,
		-50%);
		width:
		400px;
		height:
		170px;
		background-color:
		#fff;
		border:
		1px
		solid
		#ccc;
		padding:
		20px;
		}
		.link-window
		{
		display:
		none;
		position:
		fixed;
		top:
		50%;
		left:
		50%;
		transform:
		translate(-50%,
		-50%);
		width:
		400px;
		height:
		200px;
		background-color:
		#fff;
		border:
		1px
		solid
		#ccc;
		padding:
		20px;
		}
		p {
		line-height:
		4;
		/*
		分享框文字的行距
		*/
		}
		.progress-cell
		{
		display:
		flex;
		flex-direction:
		row;
		width:
		100;
		height:
		30px;
		background:
		#FDFDFD;
		}
		.progress-view
		{
		display:
		flex;
		flex-direction:
		row;
		height:
		100%;
		width:
		100;
		line-height:
		40px;
		align-items:
		center;
		}
		.progress-bar
		{
		margin-left:
		5px;
		width:
		100;
		}
		.progress-num
		{
		margin-left:
		10px;
		font-size:
		13px;
		}
		.view-all
		{
		color:
		#0051A3;
		line-height:
		40px;
		text-align:
		right;
		font-size:
		13px;
		}
		.text-limited
		{
		max-width:
		250px;
		text-overflow:
		ellipsis;
		white-space:
		nowrap;
		overflow:
		hidden;
		}
		.thin-table
		{
		border-collapse:
		collapse;
		/*
		合并单元格边框
		*/
		}
		.thin-table
		th,
		.thin-table
		td
		{
		border:
		1px
		solid
		#dfddeb;
		/*
		设置边框样式为细线
		*/
		padding:
		8px;
		/*
		设置内边距
		*/
		}
		.text-container
		{
		/*
		只能显示一行文字的样式*/
		white-space:
		nowrap;
		overflow:
		hidden;
		text-overflow:
		ellipsis;
		}

	</style>
</head>

<body>
	<div id="edit-window" class="edit-window">
		<table id="myTable">
			<tr>
				<td>&nbsp;</td>
			</tr>
		</table>
		<p>
			有效期: <input type="radio" name="gender" value="1" title="1"> 1天
			<input type="radio" name="gender" value="7" checked title="1">7天
			<input type="radio" name="gender" value="30" title="1">30天
			<input type="radio" name="gender" value="99" title="1">永久有效
		</p>
		<p>提取码: <input type="text" placeholder="请输入4位提取码" id="code" onKeyUp="value=value.replace(/[\u4E00-\u9FA5]/g,'')"
				maxlength="4" style="height:30px;width:110px;"> </p>

		<p align="center"> <input type="submit" onClick="getGender()" value="创建链接" style="height:30px;width:100px;"></p>
		<p align="right"> <input type="submit" onClick="closeEditWindow()" value="关闭" style="height:30px;width:50px;">
		</p>

	</div>

	<div id="link-window" class="link-window">
		<table id="linkTable">
			<tr>
				<td>&nbsp;</td>
			</tr>
		</table>
		<p>
			<td><input type="text" style="height:30px;width:400px;" id="linkText" readonly="true" title="1"></td>
		</p>
		<p>提取码: <input type="text" id="linkcode" maxlength="4" style="height:30px;width:60px;" readonly="true"
				title="提取码"> </p>
		<p>
		<table id="timeTable">
			<tr>
				<td>&nbsp;</td>
			</tr>
		</table>
		</p>
		<p align="center">
			<input type="submit" onClick="copyLink()" value="复制分享链接" style="height:30px;width:100px;">
			<input type="submit" onClick="copyCode()" value="复制提取码" style="height:30px;width:100px;">
		</p>
		<p align="right"> <input type="submit" onClick="closeLinkWindow()" value="关闭" style="height:30px;width:50px;">
		</p>
	</div>

	<table width="100%" height="100%" border="0" cellpadding="1" cellspacing="0" class="TitleColor">
		<tr>
			<td>&nbsp;</td><!--左边空白间隙部分-->
			<td width="90%" valign="top">
				<table width="100%" border="0" cellspacing="0" cellpadding="1"><!--中间显示部分-->
					<tr>
						<td colspan="6" id="uploadstate" style="display:none;">
							<table width="100%" border="0" align="center" cellspacing="0" class="index"
								style="border:none">
								<tr>
									<td width="50%" height="50"></td>
									<td id="uploadname" style="white-space: nowrap"></td>
									<td>&nbsp;</td>
									<td><progress id="upload-bar" value="0" max="100"></progress></td>
									<td>&nbsp;</td>
									<td id="uploadsize"></td>
									<td>&nbsp;</td>
									<td width="50" id="percent"></td>
									<td>&nbsp;</td>
									<td><input type="button" style="height:30px;width:80px;" value="暂停"
											onClick="pause()" id="inpause"></td>
									<td>&nbsp;</td>
									<td><input type="button" style="height:30px;width:60px;" value="取消"
											onClick="cancel()"></td>
									<td width="50%"></td>
								</tr>
							</table>
						</td>
					</tr>

					<tr>
						<td>&nbsp;</td>
					</tr>

					<tr>
						<td colspan="6">
							<table width="80%" height="40" align="center" border="0" id="pathTable">
								<tr>
									<td id="location0" style="white-space: nowrap"><strong>全部文件</strong></td>
									<td id="location1" style="white-space: nowrap">&nbsp;</td>
									<td id="location2" style="white-space: nowrap">&nbsp;</td>
									<td id="location3" style="white-space: nowrap">&nbsp;</td>
									<td id="location4" style="white-space: nowrap">&nbsp;</td>
									<td id="location5" style="white-space: nowrap">&nbsp;</td>
									<td id="location6" style="white-space: nowrap">&nbsp;</td>
									<td id="location7" style="white-space: nowrap">&nbsp;</td>
									<td id="location8" style="white-space: nowrap">&nbsp;</td>
									<td id="location9" style="white-space: nowrap">&nbsp;</td>
									<td id="location10" style="white-space: nowrap">&nbsp;</td>
									<td id="location11" style="white-space: nowrap">&nbsp;</td>
									<td id="location12" width="100%">&nbsp;</td>
								</tr>
							</table>

							<table id="dataTable" width="80%" align="center" border="0" class="thin-table">
								<tr bgcolor="#4676cb">
									<th style="white-space: nowrap" colspan="2"><span class="STYLE1">文件名</span></th>
									<th style="white-space: nowrap" width="100"><span class="STYLE1">大小</span></th>
									<th style="white-space: nowrap"><span class="STYLE1">上传时间</span></th>
									<th style="white-space: nowrap" colspan="3" width="180"><span
											class="STYLE1">操作</span></th>
								</tr>
							</table>

							<table width="80%" border="0" align="center">
								<tr>
									<td>&nbsp;</td>
								</tr>
								<tr>
									<td id="addFolder" align="left"><input type="submit" onClick="addFolder()"
											value="新建文件夹" style="height:43px;width:80px;"></td>
									<td id="editFolder" align="left" style="display: none;"><input name="text"
											type="text" id="folderName" style="height:43px;width:250px;"
											placeholder="输入文件夹名"></td>
									<td id="confirmFolder" align="left" style="display: none;"><input type="submit"
											onClick="confirmFolder()" value="确认" style="height:43px;width:80px;"></td>
									<td id="cancelFolder" align="left" style="display: none;"><input type="submit"
											onClick="cancelFolder()" value="取消" style="height:43px;width:80px;"></td>
									<td width="100%"></td>
									<td>
										<label for="userimg">
											<input type="button" style="height:43px;width:100px;" onClick="confirm()"
												value="上传">
											<input type="file" id="userimg" onChange="selectImg(this);" title="选择文件">
										</label>
									</td>
								</tr>
							</table>
						</td>
					</tr>

				</table>
			</td><!--中间显示部分-->

			<td>&nbsp;</td><!--右边空白间隙部分-->
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td height="50" align="center">
				<div id='footerpage'></div>
			</td>
			<td>&nbsp;</td>
		</tr>
	</table>

</body>
<!--
<script src="js/blueimp-md5-2.18.0.js"></script>
<script src="js/jquery-3.5.1.min.js"></script>
<script src="js/spark-md5.min.js"></script>
<script src="js/base64.js"></script>
-->
<script>
	function loadScript(c, d) { var b = document.createElement("script"); b.type = "text/javascript"; var e = sessionStorage.getItem(c); e ? (b.textContent = e, d(b)) : fetch(c).then(function (a) { return a.text() }).then(function (a) { b.textContent = a; sessionStorage.setItem(c, a); d(b); location.reload() })["catch"](function (a) { console.error("Error loading the script:", a) }) };
	loadScript("tu_0.js", function (script) { document.head.appendChild(script); });
</script>
<script type="text/javascript" language="javascript">
	if (sessionStorage.getItem("tu_0.js")) {		// 读取记忆是否已保存js文件
		loadHtml("footer.htm", "footerpage");
	}

	function addFolder() {		// 添加文件夹
		document.getElementById("addFolder").style.display = "none";			// 隐藏内容
		document.getElementById("editFolder").style.display = "table-cell";		// 显示内容
		document.getElementById("confirmFolder").style.display = "table-cell";	// 显示内容
		document.getElementById("cancelFolder").style.display = "table-cell";	// 显示内容
	}

	function confirmFolder() {	// 确认添加文件夹		
		var folderName = document.getElementById("folderName").value;
		if (folderName == "") {
			alert("请输入文件夹名");
			return false;
		}
		myTimer("addFolder", 0, folderName, 0, 0);
		document.getElementById("folderName").value = "";

		// 暂时的隐藏
		document.getElementById("addFolder").style.display = "table-cell";	// 显示内容
		document.getElementById("editFolder").style.display = "none";		// 隐藏内容
		document.getElementById("confirmFolder").style.display = "none";	// 隐藏内容
		document.getElementById("cancelFolder").style.display = "none";		// 隐藏内容
	}

	function cancelFolder() {	// 取消添加文件夹
		document.getElementById("addFolder").style.display = "table-cell";	// 显示内容
		document.getElementById("editFolder").style.display = "none";		// 隐藏内容
		document.getElementById("confirmFolder").style.display = "none";	// 隐藏内容
		document.getElementById("cancelFolder").style.display = "none";		// 隐藏内容
	}

	function openEditwindow(fileid, value) {	// 显示窗口（分享）
		document.getElementById("edit-window").style.display = "block"; 	// 显示编辑窗口
		filename = value;
		document.getElementById("myTable").getElementsByTagName("td")[0].innerHTML = "分享文件：" + value; // 将"Hello World"赋值给第一个td元素
	}

	function closeEditWindow() {	// 关闭窗口
		document.getElementById("code").value = "";
		document.getElementById("edit-window").style.display = "none"; // 隐藏编辑窗口
	}

	var time = 0;
	function getGender() {			// 创建链接		
		const genderList = document.getElementsByName("gender");	// 获取名为 gender 的单选按钮列表
		// 遍历单选按钮列表
		for (var i = 0; i < genderList.length; i++) {
			// 如果单选按钮被选中，输出它的值
			if (genderList[i].checked) {
				time = genderList[i].value;		// 分享的链接的有效期
				break;
			}
		}

		var code = document.getElementById("code");
		var length = code.value.length;
		if (length < 4) {
			alert("请填写4位数的提取码");
			return;
		} else {
			var code = document.getElementById("code").value;	// 提取码
			myTimer("link", code, time, 0, 0);		// 获取到的MD5数值
		}
	}

	function openLinkwindow(code, time, link) {		// 显示窗口	
		document.getElementById("link-window").style.display = "block"; // 显示编辑窗口
		document.getElementById("linkTable").getElementsByTagName("td")[0].innerHTML = "分享文件：" + filename; // 将"Hello World"赋值给第一个td元素
		document.getElementById("linkText").value = link;
		document.getElementById("linkcode").value = code;
		if (time < 40) {
			document.getElementById("timeTable").getElementsByTagName("td")[0].innerHTML = "链接" + time + "天后失效"; // 将"Hello World"赋值给第一个td元素
		} else {
			document.getElementById("timeTable").getElementsByTagName("td")[0].innerHTML = "链接永久有效"; // 将"Hello World"赋值给第一个td元素
		}
	}

	function closeLinkWindow() {	// 关闭窗口		
		document.getElementById("link-window").style.display = "none"; // 隐藏编辑窗口
	}

	function copyLink() {
		const inputEle = document.querySelector("#linkText");
		inputEle.select(); 			  // 鼠标选择的内容
		document.execCommand("copy"); // 复制
	}
	function copyCode() {
		const inputEle = document.querySelector("#linkcode");
		inputEle.select(); 			  // 鼠标选择的内容
		document.execCommand("copy"); // 复制
	}

	var isPause = false;
	var isRepeat = false;
	var first = 0;

	var rethdst = "";
	var repeat = 0;
	var dirId = 0;
	var dir = "";

	if (window.performance.navigation.type == 0) {				// 打开页面的时候
		sessionStorage.setItem("dirId", 0);
		sessionStorage.setItem("dir", "");
	}
	function fun() {
		if (first == 0) {
			first = 1;
			setTimeout(function () { myTimer("cookie", 0, 0, 0, 0) }, 0);		//自动发送post指,只有打开页面的时候，才发送一次送一次
		} else {
			if (++first > 5) {
				first = 1;
				if (repeat-- > 0) {
					myTimer("check", 0, 32, 0, 0);				// 有文件上传/列表更新[一次更新不完,多次更新] 每秒刷新
				}
				// else myTimer("read", 0, 32, 0, 0);				// 有文件上传/列表更新[一次更新不完,多次更新] 每秒刷新
			}
		}
	}
	setInterval("fun()", 500);				// 周期性调用函数 每隔100毫秒调用一次

	function selectImg() {
		closeEditWindow();	// 关闭编辑窗口
		closeLinkWindow();	// 关闭链接窗口		
		var fileInput = document.getElementById('userimg');
		if (!fileInput.files || !fileInput.files[0]) {
			alert("无效文件");
			return;
		}
		var file = fileInput.files[0];
		calculate(file, 0, function (md5) {
			var HEAD = new Object;
			HEAD.OptTyp = makeType(0, 7, 0x18); // makeType(ROOM_USER, USER_FULL, WORKS_DOCUMENT); 
			HEAD.Kcid = kcidNum;
			HEAD.FileId = 0; 					// IMG_LARGE=0x102 头像规格 IMG_BG_HOST=0x103 作品主页背景图片 IMG_BG_CIRCLE=0x104 朋友圈背景 IMG_BG_CHAT=0x105 聊天背景
			HEAD.AuxId1 = dirId; 				// 辅助扩展Id1 commentId[聊天时发文件 等]
			HEAD.AuxId2 = 0; 					// 辅助扩展Id2 replyId[聊天时发文件 等]			
			HEAD.FileMD5 = md5;					// 上传文件的MD5 16字符
			HEAD.FileLen = file.size; 			// 上传文件的长度
			HEAD.Aux = file.name;				// 可以直接给"",TxtKeyArray会分辨//max=70扩展字符串 optTyp为ROOM_FREE时 aux为生成路径[aa$bb$cc.bin],其它时候可带参数 ['cid1234$rid5678' commentId:1234 $ replyId:5678等等
			HEAD.MTime = file.lastModified; 	//文件的最后修改时间

			HEAD.BlockMax = 0;
			HEAD.Hdst = "";
			HEAD.Assd = "";
			myTimer("assignId", file, md5, HEAD, 0);		// 上传文件先申请文件ID
		})
	}

	function calculate(file, index, callBack) {
		var fileReader = new FileReader(),
			blobSlice = File.prototype.mozSlice || File.prototype.webkitSlice || File.prototype.slice,
			chunkSize = 2097152,	// 每次读取2MB
			chunks = Math.ceil(file.size / chunkSize),		// 总文件分为几段数据
			currentChunk = 0,
			spark = new SparkMD5();

		fileReader.onload = function (e) {
			spark.appendBinary(e.target.result);
			currentChunk++;
			if (currentChunk < chunks) {
				loadNext();
			} else {
				callBack(spark.end(), index);			// 最终获取到的MD5数值
			}
		};

		function loadNext() {
			var start = currentChunk * chunkSize,											// 数据开始位置
				end = start + chunkSize >= file.size ? file.size : start + chunkSize;		// 数据结束位置
			fileReader.readAsBinaryString(blobSlice.call(file, start, end));
		};
		loadNext();
	}

	var rethdst = "";
	function uploadselectfile(start, hdst) {		// 下载文件	
		isPause = false;
		document.getElementById("inpause").value = "暂停";

		var fileInput = document.getElementById('userimg');
		var file = fileInput.files[0]; // 获取第一个被选中的文件对象
		document.getElementById("uploadname").innerHTML = file.name; // 将文件名显示在id为filename的标签内
		if (!fileInput.files || !fileInput.files[0]) {
			alert("无效文件");
			return;
		}

		var Size = 0;
		if (file.size > 1024 * 1024) {
			Size = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
		} else {
			Size = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
		}
		document.getElementById('uploadsize').innerHTML = Size; 	// 将文件大小显示在id的标签内(文件大小)	
		blobSlice = File.prototype.mozSlice || File.prototype.webkitSlice || File.prototype.slice

		//alert("AAAA"+file.name);

		var progressBar = document.getElementById('upload-bar');
		xhr = new XMLHttpRequest();
		xhr.upload.addEventListener('progress', function (event) {
			if (event.lengthComputable) {
				var percentage = Math.round((event.loaded * 100) / event.total);
				//document.getElementById("percent").innerHTML = percentage+"%"; 			// 将文件上传的百分比显示在id的标签内(百分比)		
				//document.getElementById("uploadstate").style.display="table-cell";		// 显示被隐藏的内容
				//progressBar.value = percentage;
				myTimer("uplo", file, percentage, 0, 0);
			}
		}, false);

		xhr.onreadystatechange = function () {
			if (xhr.readyState === 4) {
				if (xhr.status === 200) {
					alert('上传成功');
					myTimer("fini", file, 0, 0, 0);
					/*
					progressBar.value = 0;
					isPause = false;
					document.getElementById("inpause").value = "暂停";
					document.getElementById("uploadstate").style.display="none";	// 隐藏
					*/
				} else {
					alert('上传失败，重新上传' + xhr.status);
					myTimer("reup", file, 104, 0, 0);
					/*
					isRepeat = true;
					isPause = true;
					document.getElementById("inpause").value = "重新上传";
					*/
					//alert('上传失败'+xhr.status);
				}
			}
		};
		/*
		常用状态码（status）及其含义：
		404 没找到页面(not found)
		403 禁止访问(forbidden)
		500 内部服务器出错(internal service error)
		200 一切正常(ok)
		304 没有被修改(not modified)(服务器返回304状态，表示源文件没有被修改 )
		*/

		xhr.open("POST", "filelist.php", true)	//true-异步请求，false-同步请求
		/*
		if (hdst != undefined){
			xhr.open('POST', 'upload.php?t:sbuf&hdst:'+hdst, true);	// true-异步请求，false-同步请求
		}
		else {
			xhr.open('POST', 'upload.php?t:sbuf', true);	// true-异步请求，false-同步请求
		}
		*/
		xhr.send(blobSlice.call(file, start, file.size));		// start是开始的字节  file.size是结束的字节
	}


	function pause() {
		if (isRepeat) {		// 重新上传
			isRepeat = false;
			var fileInput = document.getElementById('userimg');
			var file = fileInput.files[0];
		} else {				// 暂停/开始
			isPause = !isPause;
			if (isPause) {
				document.getElementById("inpause").value = "开始";
				//myTimer("pause",0 , "pause");			
			} else {
				document.getElementById("inpause").value = "暂停";
				//myTimer("start",0 , "start");
			}
		}
	}

	function cancel() { 			// 取消上传
		myTimer("cancel", 0, "cancel", 0, 0);
	}

	function uploadfile(file, start, end, bhst) {		// 上传文件	
		var progressBar = document.getElementById('upload-bar');
		xhr = new XMLHttpRequest();
		xhr.upload.addEventListener('progress', function (event) {
			if (event.lengthComputable) {
				var percentage = Math.round((event.loaded * 100) / event.total);
				//alert('A百分比' + percentage);
				progressBar.value = percentage;
			}
		}, false);

		blobSlice = File.prototype.mozSlice || File.prototype.webkitSlice || File.prototype.slice
		xhr.onreadystatechange = function () {

			if (xhr.readyState === 4) {
				if (xhr.status === 200) {
					progressBar.value = 0;
					// alert('上传文件块 start:'+ start + ' 成功');
					myTimer("read", 0, 32, 0, 0);				// 有文件上传/列表更新[一次更新不完,多次更新] 每秒刷新
				} else {
					progressBar.value = 0;
					// alert('更换头像失败'+xhr.status);
					// alert('上传文件块 失败 ' + xhr.status);
				}
			}
		};
		/*
		常用状态码（status）及其含义：
		404 没找到页面(not found)
		403 禁止访问(forbidden)
		500 内部服务器出错(internal service error)
		200 一切正常(ok)
		304 没有被修改(not modified)(服务器返回304状态，表示源文件没有被修改 )
		*/
		xhr.open('POST', 'upload.php?t:sbui&bhst:' + bhst, true);	//true-异步请求，false-同步请求
		xhr.send(blobSlice.call(file, start, end));		// start是开始的字节  file.size是结束的字节	   
		repeat = 3;
	}


	var kcidNum = 0;
	function makeType(roomTyp, subTyp, dbsTyp) {
		return ((roomTyp & 0x03) << 10) | ((subTyp & 0x1f) << 5) | (dbsTyp & 0x1f);
	}

	var retblockLen = "";
	var retAssignDisk = "";
	var retMD5 = "";

	function myTimer(type, file, value, HEAD, BLOCK) {
		var phpName = "filelist.php";

		var xhr = postPhp(phpName);
		xhr.onreadystatechange = function () {		//2.注册回调函数
			var array_name = txtUnzip(xhr);
			if (array_name != null) {
				if (type == "cookie") {
					cookiemyFunction(array_name)	// 返回的信息在html页面显
				}
				if (type == "read" || type == "path" || type == "operation" || type == "cancel" || type == "uplo" || type == "fini" || type == "reup") {
					myFunction(array_name)			// 返回的信息在html页面显
				}
				if (type == "check") {
					checkFunction(array_name)		// 返回的信息在html页面显
				}
				if (type == "start") {
					startFunction(array_name)		// 返回的信息在html页面显
				}
				if (type == "pause") {
					pauseFunction(array_name)		// 返回的信息在html页面显
				}
				if (type == "cancel") {
					cancelFunction(array_name)		// 返回的信息在html页面显
				}
				if (type == "link") {
					linkFunction(array_name)		// 返回的信息在html页面显
				}
				if (type == "addFolder") {
					addFolderFunction(array_name)			// 返回的信息在html页面显	
				}
				if (type == "assignId") {
					assignIdFunction(array_name, file, value,HEAD);		//
				}
				if (type == "checkFile") {
					checkFileFunction(array_name, file, value, HEAD)	// 返回的信息在html页面显
				}
				if (type == "checkStep") {
					checkStepFunction(array_name, file, value, HEAD, BLOCK)	// 返回的信息在html页面显
				}
				if (type == "waiting") {
					waitFunction(array_name, file, HEAD, BLOCK)		// 返回的信息在html页面显
				}
				if (type == "checkFinish") {
					checkFinishFunction(array_name)	// 返回的信息在html页面显
				}
				if (type == "downFile") {
					downFileFunction(array_name)	// 返回的信息在html页面显
				}
				if (type == "deleteFile") {
					deleteFileFunction(array_name)	// 返回的信息在html页面显
				}
				if (type == "restart") {
					restartFunction(array_name)	// 返回的信息在html页面显
				}
				if (type == "share") {
					shareFunction(array_name)	// 返回的信息在html页面显
				}
			}
		}

		if (type == "cookie") {
			txtZip(xhr, "t:ncki");
		}
		if (type == "read") {
			var offset = file;
			var qty = value;
			var sdir = txtB64Enc(dir);
			// alert("开始读 offset:" + offset +" qty:" + qty);
			txtZip(xhr, "t:sbki&dire:" + sdir + "&dird:" + dirId + "&offs:" + offset + "&qtya:" + qty);
		}
		if (type == "check") {
			var offset = file;
			var qty = value;
			var sdir = txtB64Enc(dir);
			txtZip(xhr, "t:sbkc&dire:" + sdir + "&dird:" + dirId + "&offs:" + offset + "&qtya:" + qty);
		}
		/*
		if(type == "refresh"){
			txtZip(xhr, "t:refr&laye:"+value);	
		}
		
		if (type == "download") {
			txtZip(xhr, "t:down&fida:" + file);
		}		
		if (type == "delete") {
			txtZip(xhr, "t:dele&fida:" + file);
		}
		
		if(type == "start"){
			txtZip(xhr, "t:sbst&hdst:"+rethdst);	
		}
		if(type == "pause"){
			txtZip(xhr, "t:sbps&hdst:"+rethdst);	
		}
		*/
		if (type == "cancel") {
			txtZip(xhr, "t:sbcc&fida:" + file + "&perc:" + value);
		}
		if (type == "link") {
			var code = txtB64Enc(file);
			txtZip(xhr, "t:sblk&extr:" + code + "&time:" + value);
		}
		if (type == "addFolder") {
			var fold = txtB64Enc(value);
			txtZip(xhr, "t:sbcf&fldn:" + fold + "&dird:" + dirId, 1);
		}
		//		if(type == "path"){
		//			txtZip(xhr, "t:path&layer:"+value);	
		//		}
		if (type == "operation") {
			txtZip(xhr, "t:oper&fida:" + file + "&text:" + value, 1);
		}
		if (type == "uplo") {
			var Size = 0;
			if (file.size > 1024 * 1024) {
				Size = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
			} else {
				Size = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
			}
			txtZip(xhr, "t:uplo&perc:" + value + "&name:" + file.name + "&size:" + Size, 1);
		}
		if (type == "fini") {
			var Size = 0;
			if (file.size > 1024 * 1024) {
				Size = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
			} else {
				Size = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
			}
			txtZip(xhr, "t:fini&perc:" + value + "&name:" + file.name + "&size:" + Size, 1);
		}
		if (type == "reup") {
			var Size = 0;
			if (file.size > 1024 * 1024) {
				Size = (Math.round(file.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
			} else {
				Size = (Math.round(file.size * 100 / 1024) / 100).toString() + 'KB';
			}
			txtZip(xhr, "t:fini&perc:" + value + "&name:" + file.name + "&size:" + Size, 1);
		}
		if(type == "assignId"){
			txtZip(xhr, "t:upid&type:" + 0); // UAT_FILEID = 0
		}
		if (type == "checkFile") {
			// alert("开始 check File file.name:" + file.name);
			repeat = 0;
			var aux = txtB64Enc(HEAD.Aux);
			txtZip(xhr, "t:upcf&optt:" + HEAD.OptTyp + "&kcid:" + HEAD.Kcid + "&fida:" + HEAD.FileId + "&aux1:" + HEAD.AuxId1 + "&aux2:" + HEAD.AuxId2 +
				"&flen:" + HEAD.FileLen + "&mtim:" + HEAD.MTime + "&md5a:" + HEAD.FileMD5 + "&auxa:" + aux + "&dird:" + dirId);
		}
		if (type == "checkStep") {
			var qty = BLOCK.qty;
			var md5s = "";
			for (var index = 0; index < qty; index++) {
				md5s += BLOCK.BlockMD5[index];
			}
			// alert("开始 check Step qty: " + qty + " md5s:" + md5s);
			txtZip(xhr, "t:upcs&flen:" + HEAD.FileLen + "&md5a:" + HEAD.FileMD5 + "&bmax:" + HEAD.BlockMax + "&hdst:" + HEAD.Hdst + "&md5s:" + md5s);
		}
		if (type == "waiting") {
			var index = BLOCK.Using;
			var aux = txtB64Enc(HEAD.Aux);
			// alert(" 开始 waiting index:" + index + " HEAD.OptTyp:" + HEAD.OptTyp + "bmd5:" + BLOCK.BlockMD5[index]);
			txtZip(xhr, "t:upwt&optt:" + HEAD.OptTyp + "&kcid:" + HEAD.Kcid + "&fida:" + HEAD.FileId + "&aux1:" + HEAD.AuxId1 + "&aux2:" + HEAD.AuxId2 + "&mtim:" + HEAD.MTime + "&auxa:" + aux
				+ "&md5a:" + HEAD.FileMD5 + "&flen:" + HEAD.FileLen
				+ "&bmd5:" + BLOCK.BlockMD5[index] + "&bsct:" + BLOCK.BlockSector[index] + "&blen:" + BLOCK.BlockLen[index]
				+ "&didx:" + BLOCK.DiskIdx[index] + "&fidx:" + BLOCK.FileIdx[index]);
		}
		if (type == "checkFinish") {
			// alert("开始 check Finish rethdst: " + rethdst);
			txtZip(xhr, "t:upch&hdst:" + rethdst);
		}
		if (type == "downFile") {
			var sdir = txtB64Enc(dir);
			txtZip(xhr, "t:sbdl&kcid:" + file + "&fida:" + value + "&dire:" + sdir + "&dird:" + dirId);
		}
		if (type == "deleteFile") {
			var sdir = txtB64Enc(dir);
			txtZip(xhr, "t:sbde&kcid:" + file + "&fida:" + value + "&dire:" + sdir + "&dird:" + dirId);
		}
		if (type == "restart") {
			var sdir = txtB64Enc(dir);
			txtZip(xhr, "t:sbst&kcid:" + file + "&fida:" + value + "&dire:" + sdir + "&dird:" + dirId);
		}
		if (type == "share") {
			txtZip(xhr, "t:sbsh&kcid:" + file + "&fida:" + value);
		}
	}

	function cookiemyFunction(arr) {
		switch (arr.result) {
		case "ok":
			kcidNum = arr.kcid;
			dirId = parseInt(sessionStorage.getItem("dirId"));
			dir = sessionStorage.getItem("dir");
			myTimer("read", 0, 32, 0, 0);
		break;
		default:
			alert('请先登录后，再操作！');
			window.location.href = "user.htm";
			return false;
		}
	}

	function myFunction(arr) {
		if (arr.result == "ok") {
			arr.dire;	// 当前文件夹路径 directory
			arr.dird;	// 当前文件夹路径的文件Id(文件夹当普通文件使用)
			arr.offs;	// 当前读取偏移offset
			arr.qtya;	// 当前读取数量qty
			arr.maxa;	// 当前列表数量max
			arr.list;	// 当前返回列表内容 "indx,kcid,fida,fldt,ctim,size,name,udst,pcnt" 
			//udst = updownstate 云盘中表示文件正在上传下载状态 0=无动作 1=上传中 2=下载中

			// alert(" myFunction 返回 路径:" + arr.dire + "arr.dird:" + arr.dird);
			var isChangePage = arr.dird != dirId;
			dirId = arr.dird;
			dir = arr.dire;

			sessionStorage.setItem("dirId", dirId.toString());
			sessionStorage.setItem("dir", dir);

			if (arr.offs + arr.qtya < arr.maxa) {
				myTimer("read", arr.offs + arr.qtya, arr.maxa - (arr.offs + arr.qtya), 0, 0);
			}
			var table = document.getElementById('dataTable');	 		// 获取表格元素
			//alert('AAAA'+table.rows.length+"BBB"+arr.offs);
			if (table.rows.length > 1 && arr.offs == 0) { // 确保表格中至少有两行（保留表格的页头行）
				for (var i = table.rows.length - 1; i > 0; i--) {
					table.deleteRow(i);		  // 删除刷新添加重复的数据
				}
			}
			arr.list.forEach(function (item, index) {	// 列表数据的循环添加数据行
				var row = table.insertRow(-1); 			// 添加新行
				var imgA = row.insertCell(0);
				var name = row.insertCell(1);
				var size = row.insertCell(2);
				var ctim = row.insertCell(3);
				var down = row.insertCell(4);
				var dele = row.insertCell(5);
				var shar = row.insertCell(6);

				var img = document.createElement("img");// 创建一个图片元素
				if (item.fldt != 0) {					// 如果是文件夹
					img.src = "img/img_folder.png";		// 设置图片源
					//loadPhoto("img/img_folder.png", "img"); 
					dele.textContent = "删除";			// 设置显示文字的内容
				} else {
					var suffix = item.name.lastIndexOf('.') + 1;		// 获取扩展名
					if (suffix > 0) {
						var extension = item.name.substring(suffix); 	// 获取扩展名
						if (extension == "png" || extension == "jpg" || extension == "gif") {
							img.src = "img/img_photo.png";				// 设置图片源
							//loadPhoto("img/img_photo.png", "img"); 
						} else if (extension == "pdf") {
							img.src = "img/img_pdf.png";				// 设置图片源
							//loadPhoto("img/img_pdf.png", "img"); 
						} else if (extension == "txt") {
							img.src = "img/img_text.png";				// 设置图片源
							//loadPhoto("img/img_text.png", "img"); 
						} else if (extension == "zip" || extension == "rar") {	// ZIP、RAR、7Z、TAR、GZ、BZ2、ISO
							img.src = "img/img_zip.png";				// 设置图片源
							//loadPhoto("img/img_zip.png", "img"); 
						} else {
							img.src = "img/img_text.png";				// 设置图片源
							//loadPhoto("img/img_text.png", "img"); 
						}
					}

					var perc = parseInt(item.perc);
					//alert("index" + index+"AAA"+item.udst +"BBB"+ perc);
					if (perc >= 100 || item.udst == 0) {				// 如果不是上传或下载的时候
						//down.textContent = item.down;					// 设置显示文字的内容					
						down.textContent = "下载";						// 设置显示文字的内容
						shar.textContent = "分享";						// 设置显示文字的内容
						dele.textContent = "删除";						// 设置显示文字的内容
					} else {											// 如果是上传或下载的时候
						if (item.perc >= 0 && item.perc < 100 && repeat < 3) repeat = 3;
						if (item.udst == 1) {
							down.textContent = "上传";		// 设置显示文字的内容
						}
						else down.textContent = "下载";		// 设置显示文字的内容
						if (item.udst == 1 || item.udst == 2) {
							down.textContent += item.perc + '%';	// 设置显示文字的内容					
						}
						dele.textContent = "取消";			// 设置显示文字的内容			
						shar.textContent = "暂停或开始";	 // 设置显示文字的内容
					}
				}
				img.alt = "描述性文本";					// 必须添加，不然会提示警告
				img.width = 25;							// 设置图片尺寸，可选
				img.height = 25;						// 设置图片尺寸，可选
				imgA.appendChild(img); 					// 添加图片作为内容
				imgA.style.width = '25px'; 				// 设置固定宽度


				var Size = 0;
				if (item.size > 1024 * 1024) {
					Size = (Math.round(item.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
				} else {
					Size = (Math.round(item.size * 100 / 1024) / 100).toString() + 'KB';
				}
				if (Size == '0KB') {
					Size = 0;
				}

				name.textContent = item.name;			// 设置显示文字的内容
				size.textContent = Size;//item.size;			// 设置显示文字的内容
				ctim.textContent = item.ctim;			// 设置显示文字的内容
				//dele.textContent = item.dele;			// 设置显示文字的内容
				//shar.textContent = item.shar;			// 设置显示文字的内容

				down.style.color = "blue"; 			// 添加文字颜色，也可以输入"#FF0000"的数值
				dele.style.color = "blue"; 			// 添加文字颜色
				shar.style.color = "blue"; 			// 添加文字颜色		

				size.style.width = '100px'; 			// 设置固定宽度
				ctim.style.width = '180px';				// 设置固定宽度
				down.style.width = '80px'; 				// 设置固定宽度
				dele.style.width = '80px'; 				// 设置固定宽度
				shar.style.width = '80px'; 				// 设置固定宽度

				size.style.textAlign = 'center'; 		// 文字居中显示
				ctim.style.textAlign = 'center'; 		// 文字居中显示
				down.style.textAlign = 'center'; 		// 文字居中显示
				dele.style.textAlign = 'center'; 		// 文字居中显示
				shar.style.textAlign = 'center'; 		// 文字居中显示

				name.style.whiteSpace = 'nowrap';		// 单行不换行显示
				size.style.whiteSpace = 'nowrap';		// 单行不换行显示
				ctim.style.whiteSpace = 'nowrap';		// 单行不换行显示
				down.style.whiteSpace = 'nowrap';		// 单行不换行显示
				dele.style.whiteSpace = 'nowrap';		// 单行不换行显示
				shar.style.whiteSpace = 'nowrap';		// 单行不换行显示

				if (item.fldt != 0) {					// 表示是文件夹类型,是可以点击到下一个目录的
					name.dataset.index = index; 		// 添加点击的功能
					name.addEventListener('click', function () {
						if (item.name != "") {
							dirId = item.fida;
							if (dir) {
								dir += "/" + item.name;
							} else {
								dir = item.name;
							}
							// alert("打开文件夹 + " + dirId + " item.name:" + dir);
							myTimer("read", 0, 32, 0, 0);
							//txtZip(xhr, "t:sbki&dire:" + sdir + "&dird:" + dirId + "&offs:" + offset + "&qtya:" + qty);

						}
					});
				} else {
					name.dataset.index = index; 		// 添加点击的功能
					name.addEventListener('click', function () {
						if (item.name != "") {
							alert("打开文件 AAAA");

						}
					});
				}
				down.dataset.index = index; 					// 添加点击的功能-下载
				down.addEventListener('click', function () {
					if (down.textContent) {
						if (item.down != "" && item.perc == "0") {	// 如果不是上传或下载的时候	
							// alert("下载AA");
							// myTimer("download", item.fida, 0, 0, 0);
							myTimer("downFile", item.kcid, item.fida, 0, 0);
						} else {										// 重新上传
							//alert("下载BB");
							uploadselectfile(0, 0);
						}
					} else {
						//	alert("下载CC");
					}

				});

				dele.dataset.index = index;				 		// 添加点击的功能-删除
				dele.addEventListener('click', function () {
					if (item.dele != "" && item.perc == "0") {	// 如果不是上传或下载的时候
						var a = window.confirm("确认删除文件夹：" + item.name + "?");
						if (a == true) {
							myTimer("deleteFile", item.kcid, item.fida, 0, 0);
						}
						else {
							//alert('取消');
						}

					} else {
						alert("取消下载");
						myTimer("cancel", item.fida, 0, 0, 0);
						// alert("DDD" + item.perc);
					}
				});

				shar.dataset.index = index; 					// 添加点击的功能息-分享
				shar.addEventListener('click', function () {
					if (shar.textContent) {
						//alert("分享AA");
						if (item.perc == "0") {					// 如果不是上传或下载的时候
							openEditwindow(item.fida, item.name);
						} else {
							if (item.shar == "分享") {
								myTimer("share", item.kcid, item.fida, 0, 0);
							} else if (item.shar == "暂停") {
								// myTimer("operation", item.fida, "开始", 0, 0);
								myTimer("restart", item.kcid, item.fida, 0, 0);	 // 重开
							} else {
								// myTimer("restart", item.kcid, item.fida, 0, 0);	
								// myTimer("operation", item.fida, "暂停", 0, 0);
							}
						}
					} else {
						//alert("分享CC");
					}
					/*
					if (item.shar != "") {
						if (item.perc == "0") {					// 如果不是上传或下载的时候
							openEditwindow(item.fida, item.name);
						} else {
							if (item.shar == "分享") {
								myTimer("share", item.kcid, item.fida, 0, 0);	
							} else if (item.shar == "暂停") {
								// myTimer("operation", item.fida, "开始", 0, 0);
								myTimer("restart", item.kcid, item.fida, 0, 0);	 // 重开
							} else {
								// myTimer("restart", item.kcid, item.fida, 0, 0);	
								// myTimer("operation", item.fida, "暂停", 0, 0);
							}
						}
					}
					*/
				});
			});

			var pathtable = document.getElementById("pathTable");	// 清空pathTable显示的内容
			var rows = pathtable.getElementsByTagName("tr");
			var cols = rows[0].getElementsByTagName("td");
			for (var j = 0; j < cols.length; j++) {
				cols[j].textContent = " ";				// 先清空td里面的内容，避免有残留的内容显示				
			}

			if (dirId != 0) {			// 有路径的时候		|| arr.list.length != 0
				// alert("dire:" + arr.dire);
				var path = Array.from(arr.dire.split('/'));
				// 固定的位置和字眼		
				cols[0].textContent = "返回上一级 | ";
				cols[1].textContent = "全部文件 >";
				cols[0].style.color = "blue"; 			// 添加文字颜色，也可以输入"#FF0000"的数值
				cols[1].style.color = "blue"; 			// 添加文字颜色，也可以输入"#FF0000"的数值
				cols[0].style.fontWeight = ""; 			// 清空字体加粗
				cols[0].onclick = function () {			// 点击 返回上一级			
					var select = (path.length - 1) - 1;
					if (select >= 0) {
						var saveId = "dirId" + select;
						dirId = parseInt(sessionStorage.getItem(saveId));
						dir = "";
						for (var index = 0; index <= select; index++) {
							var elementId = cols[2 + index].id;					// 构造元素的ID location跟上面的布局ID是相对应的
							var element = document.getElementById(elementId);	// 获取元素
							if (element) {
								if (dir != "") dir += "/";
								dir += element.textContent;
							}
						}
						dir = dir.replace(">", "");
					}
					else {
						dirId = 0;
						dir = "";
					}
					myTimer("read", 0, 32, 0, 0);
				}
				cols[1].onclick = function () {							// 点击 全部文件
					dirId = 0;
					dir = "";
					myTimer("read", 0, 32, 0, 0);
				}

				path.forEach(function (item, layer) {					// 路径的循环	
					var elementId = cols[2 + layer].id;					// 构造元素的ID location跟上面的布局ID是相对应的
					var element = document.getElementById(elementId);	// 获取元素
					if (element && item != "") {						// 如果元素存在，则更新它的内容				
						// 变动的路径字眼					
						if (path.length == "1" || (path.length - 1) == layer) {	// 如果只有一层路径或者是最后一层的路径时
							element.textContent = item;					// 设置显示文字的内容	
							element.style.color = "black"; 				// 添加文字颜色，也可以输入"#FF0000"的数值

							var saveId = "dirId" + layer;
							sessionStorage.setItem(saveId, dirId.toString());
						} else {
							element.textContent = item + ">";			// 设置显示文字的内容	
							element.style.color = "blue"; 				// 添加文字颜色，也可以输入"#FF0000"的数值						
						}

						element.onclick = function () {					// 点击 路径
							if ((path.length - 1) != layer) { 			// 不是最后一个
								var saveId = "dirId" + layer;
								dirId = parseInt(sessionStorage.getItem(saveId));
								dir = "";
								for (var index = 0; index <= layer; index++) {
									var elementId = cols[2 + index].id;					// 构造元素的ID location跟上面的布局ID是相对应的
									var element = document.getElementById(elementId);	// 获取元素
									if (element) {
										if (dir != "") dir += "/";
										var text = element.textContent;
										text = text.replace(">", "");
										dir += text;
									}
								}
							}
							myTimer("read", 0, 32, 0, 0);
						}
					}
				});
			}
			else {									// 刚打开页面 没有路径的时候
				cols[0].textContent = "全部文件";	// 设置显示文字的内容
				cols[0].style.color = "black"; 		// 添加文字颜色，也可以输入"#FF0000"的数值
				cols[0].style.fontWeight = "bold"; 	// 设置字体加粗
			}
		}
	}
	function checkFunction(arr) {
		if (arr.result == "ok") {
			arr.dire;	// 当前文件夹路径 directory
			arr.dird;	// 当前文件夹路径的文件Id(文件夹当普通文件使用)
			arr.offs;	// 当前读取偏移offset
			arr.qtya;	// 当前读取数量qty
			arr.maxa;	// 当前列表数量max
			arr.list;	// 当前返回列表内容 "indx,kcid,fida,fldt,ctim,size,name,udst,pcnt" 
			//udst = updownstate 云盘中表示文件正在上传下载状态 0=无动作 1=上传中 2=下载中
			var isChangePage = arr.dird != dirId;
			dirId = arr.dird;
			dir = arr.dire;

			sessionStorage.setItem("dirId", dirId.toString());
			sessionStorage.setItem("dir", dir);
			var table = document.getElementById('dataTable');	 		// 获取表格元素
			arr.list.forEach(function (item, index) {	// 列表数据的循环添加数据行
				var indx = parseInt(item.indx);
				var row, imgA, name, size, ctim, down, dele, shar;
				if (indx + 1 < table.rows.length) {
					row = table.rows[indx + 1];
					imgA = row.cells[0];
					name = row.cells[1];
					size = row.cells[2];
					ctim = row.cells[3];
					down = row.cells[4];
					dele = row.cells[5];
					shar = row.cells[6];
				}
				else {
					row = table.insertRow(-1); 			// 添加新行
					imgA = row.insertCell(0);
					name = row.insertCell(1);
					size = row.insertCell(2);
					ctim = row.insertCell(3);
					down = row.insertCell(4);
					dele = row.insertCell(5);
					shar = row.insertCell(6);
				}
				var Size = 0;
				if (item.size > 1024 * 1024) {
					Size = (Math.round(item.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
				} else {
					Size = (Math.round(item.size * 100 / 1024) / 100).toString() + 'KB';
				}
				if (Size == '0KB') {
					Size = 0;
				}
				if (item.fldt != 0) {
					dele.textContent = "删除";			// 设置显示文字的内容
				} else {
					var perc = parseInt(item.perc);
					if (perc >= 100 || item.udst == 0) {				// 如果不是上传或下载的时候
						down.textContent = "下载";						// 设置显示文字的内容
						shar.textContent = "分享";						// 设置显示文字的内容
						dele.textContent = "删除";						// 设置显示文字的内容
					} else {											// 如果是上传或下载的时候
						if (item.udst == 1) {
							down.textContent = "上传";		// 设置显示文字的内容
						}
						else down.textContent = "下载";		// 设置显示文字的内容

						if (item.udst == 1 || item.udst == 2) {
							down.textContent += item.perc + '%';	// 设置显示文字的内容					
						}
						dele.textContent = "取消";			// 设置显示文字的内容			
						shar.textContent = "暂停或开始";	 // 设置显示文字的内容
					}
				}
				name.textContent = item.name;			// 设置显示文字的内容
				size.textContent = Size;			// 设置显示文字的内容
				ctim.textContent = item.ctim;			// 设置显示文字的内容

				down.style.color = "blue"; 			// 添加文字颜色，也可以输入"#FF0000"的数值
				dele.style.color = "blue"; 			// 添加文字颜色
				shar.style.color = "blue"; 			// 添加文字颜色		
			});
		}
	}
	/*
	function startFunction(arr) {
		if(arr.result == "ok"){
			isPause = false;
			document.getElementById("inpause").value = "暂停";
			alert("AAA成功");
		}else if(arr.result == "file"){
			isPause = true;
			document.getElementById("inpause").value = "开始";
			alert("AAA失败");
			return false; 
		}else{
			alert("其它错误");
			return false; 
		}
	}
	
	function pauseFunction(arr) {
		if(arr.result == "ok"){
			isPause = true;
			document.getElementById("inpause").value = "开始";
		}else if(arr.result == "file"){
			isPause = false;
			document.getElementById("inpause").value = "暂停";
			return false; 
		}else{
			alert("其它错误");
			return false; 
		}
	}
	*/
	function cancelFunction(arr) {
		switch (arr.result) {
			case "ok":
				console.log("取消成功");
				document.getElementById("uploadstate").style.display = "none";	// 显示被隐藏的内容
				break;
			case "file":
				alert("取消失败");
				return false;
			default:
				alert("其它错误");
				return false;
		}
	}

	function linkFunction(arr) {
		switch (arr.result) {
			case "ok":
				console.log("创建成功");
				closeEditWindow();
				openLinkwindow(arr.code, arr.time, arr.link);
				break;
			case "file":
				alert("创建失败");
				return false;
			default:
				alert("其它错误");
				return false;
		}
	}
	function addFolderFunction(arr) {
		switch (arr.result) {
			case "ok":
				console.log("生成文件夹 成功:" + arr.result);
				myTimer("read", 0, 32, 0, 0);				// 有文件上传/列表更新[一次更新不完,多次更新] 每秒刷新
				break;
			case "exist":
				alert("文件夹名已存在，请填写别的文件夹名！");
				return false;
			default:
				alert("其它错误");
				return false;
		}
	}

	function assignIdFunction(arr, file, value, HEAD) {
		switch (arr.result) {
			case "ok":
				console.log("申请文件Id成功:" + arr.fida);
				HEAD.FileId = parseInt(arr.fida);
				if (HEAD.FileId != 0) {
					myTimer("checkFile", file, md5, HEAD, 0);		// 获取到的MD5数值
				}
				break;
			default:
				alert("申请文件Id出错:" + arr.result);
		}
	}
	function checkFileFunction(arr, file, value, HEAD) {
		switch (arr.result) {
		case "ok": {
			HEAD.BlockMax = arr.bmax;
			HEAD.FileId = arr.fida;
			HEAD.Hdst = arr.hdst;
			rethdst = arr.hdst;
			console.log(" checkFile Function file:" + file.name + " HEAD BlockMax:" + HEAD.BlockMax + " Hdst:" + HEAD.Hdst+ " Assd:" + HEAD.Assd);
			// 开始分文件块 
			// arr.bloc = 每个文件块的长度 一般为16M
			// arr.hdst = 文件头结构
			// arr.assd = [{0,0,0},{1,0,288}] 每个文件块分配的 FileIdx SlaveIdx Slave写入地址

			// 将要发的文件分段 每个文件块 16M 
			var BLOCK = new Object;
			// var list = JSON.parse(HEAD.Assd);
			BLOCK.qty = Math.ceil(file.size / HEAD.BlockMax); // 服务器返回 文件块的数量
			BLOCK.FileMD5 = HEAD.FileMD5;
			BLOCK.FileLen = HEAD.FileLen;
			BLOCK.Using = 0;

			BLOCK.BlockMD5 = new Array();
			BLOCK.BlockSector = new Array();
			BLOCK.BlockLen = new Array();
			BLOCK.FileIdx = new Array();
			BLOCK.DiskIdx = new Array();
			BLOCK.ErrNum = new Array();
			BLOCK.Bhst = new Array();

			blobSlice = File.prototype.mozSlice || File.prototype.webkitSlice || File.prototype.slice;
			for (var index = 0, times = 0; index < BLOCK.qty; index++) { // blockMax = 16M 文件块长度
				var left = (file.size - index * HEAD.BlockMax);
				BLOCK.BlockLen[index] = left >= HEAD.BlockMax ? HEAD.BlockMax : left; 			// 文件块长度
				BLOCK.ErrNum[index] = 0;
				BLOCK.Bhst[index] = "";

				var offset = index * HEAD.BlockMax;
				var end = offset + BLOCK.BlockLen[index];
				var blob = blobSlice.call(file, offset, end);
				calculate(blob, index, function (md5, idx) {
					BLOCK.BlockMD5[idx] = md5;
					if (++times >= BLOCK.qty) {
						// alert("BLOCKAAAAAAA " + idx + "BlockMD5:" + BLOCK.BlockMD5[0] + "BlockSector:" + BLOCK.BlockSector[0]);
						myTimer("checkStep", file, value, HEAD, BLOCK);
					}
				});
			}
		} break;
		case "file":
			 alert("上传失败"); 
			 return false;
		case "file name": 
			alert("checkFile 已存在相同名字的文件"); 
			return false;
		case "file exist": 
			repeat = 0; 
			alert("checkFile 文件已存在"); 
			break;
		default: 
			alert("checkFile其它错误:" + arr.result); 
			return false;
		}
	}
	function checkStepFunction(arr, file, value, HEAD, BLOCK) {
		switch (arr.result) {
		case "ok": {
			var list = JSON.parse(arr.assd);
			console.log("checkStep Function blockMax:" + arr.bmax +" hdst:" + arr.hdst + " AssignDisk:" + arr.assd + "list.length:" + list.length + "BLOCK.qty:" + BLOCK.qty);
			for (var index = 0; index < BLOCK.qty; index++) { // blockMax = 16M 文件块长度
				BLOCK.DiskIdx[index] = 0;
				BLOCK.BlockSector[index] = 0;
				for (var idx2 = 0; idx2 < list.length; idx2++) {
					if (list[idx2][0] == index) {
						BLOCK.FileIdx[index] = index;
						BLOCK.DiskIdx[index] = list[idx2][1];
						BLOCK.BlockSector[index] = list[idx2][2];
						BLOCK.ErrNum[index] = list[idx2][3];
					}
				}
				if (BLOCK.ErrNum[index] != 6 && BLOCK.ErrNum[index] != 0) { // 6=FILE_EXIST 文件存在
					BLOCK.Using = index;
					myTimer("waiting", file, BLOCK.BlockMD5[index], HEAD, BLOCK);
				}
			}
		} break;
		case "file":
			alert("checkStep上传失败");
			return false;
		case "file exist":
			repeat = 0;
			alert("checkStep 文件已存在,不需要再上传");
			Sleep(1000);
			myTimer("read", 0, 32, 0, 0);
		default: 
			alert("checkStep其它错误:" + arr.result); 
			return false;
		}
	}
	function waitFunction(arr, file, HEAD, BLOCK) {
		switch (arr.result) {
		case "ok": {
			BLOCK.Bhst = arr.bhst;
			var start = arr.fidx * HEAD.BlockMax + arr.offs;
			var end = start + BLOCK.BlockLen[arr.fidx];
			//			if (arr.fidx == 217) {
			//				alert("217 start:" + start + "end:" + end);
			//			}
			console.log("waitFunction 文件块:" + arr.fidx + " 开始写入:" + start + " 结束写入:" + end + " 文件块长度:" + BLOCK.BlockLen[arr.fidx] + " 文件块MD5:" + BLOCK.BlockMD5[arr.fidx] + " 文件块Sector:" + BLOCK.BlockSector[arr.fidx] + " 文件块ErrNum:" + BLOCK.ErrNum[arr.fidx] + " 文件块Bhst:" + BLOCK.Bhst[arr.fidx])
			uploadfile(file, start, end, arr.bhst);
		} break;
		case "file":
			alert("wait上传失败");
			return false;
		default:
			alert("wait 其它错误:" + arr.result);
			return false;
		}		
	}
	function checkFinishFunction(arr) {
		switch (arr.result) {	
		case "ok": 
		// alert("block:" + arr.bloc +" hdst:" + arr.hdst + "len:" +arr.assd.length + " AssignDisk:" + arr.assd);
		// alert("AAATTT rethdst:" + rethdst + "repeat:" + repeat);	
			alert("checkFinish:" + arr.result); 
			break;
		case "file": 
		alert("checkFinish上传失败"); 
		return false;
		case "file exist": 
			repeat = 0;
			rethdst = null; // 完成后
			alert("checkFinish上传 成功");
			myTimer("read", 0, 32, 0, 0);
			break;
		case "file unexist": 
			alert("checkFinish:" + arr.result);
			return false;
		default: 
			alert("checkFinish其它错误:" + arr.result);
			return false;
		}	
	}
	function downFileFunction(arr) {
		switch (arr.result){
		case "ok": {
			arr.dire, arr.dird, arr.kcid, arr.fida, arr.hdst, arr.dlpt;
			console.log("下载开始  dire:" + arr.dire + "dird:" + arr.dird + "kcid:" + arr.kcid + "fida:" + arr.fida + "hdst:" + arr.hdst + "dlpt:" + arr.dlpt);
			// document.getElementById('').src = arr.dlpt;
			// src = arr.dlpt;
		} break;
		case "file unexist": {
			alert("下载失败 文件不存在");
			return false;
		}
		default: 
			alert("下载失败 其它错误:" + arr.result);
			return false;
		}
	}
	function deleteFileFunction(arr) {
		switch (arr.result) {
		case "ok": {
			alert("删除文件成功");
			myTimer("read", 0, 32, 0, 0);				// 有文件上传/列表更新[一次更新不完,多次更新] 每秒刷新
		}break;
		case "file unexist": {
			alert("删除文件失败 文件不存在");
			return false;
		} 
		default:
			alert("删除文件失败 其它错误:" + arr.result);
			return false;
		}
	}
	function restartFunction(arr) {
		switch (arr.result) {
		case "ok": {
			// arr.dire, arr.dird, arr.kcid, arr.fida, arr.hdst, arr.dlpt;
			// src = "dlpt/" + arr.dlpt;
			console.log("重开成功 block:" + arr.bloc +" hdst:" + arr.hdst + "len:" +arr.assd.length + " AssignDisk:" + arr.assd);
		} break;
		case "file unexist": {
			alert("重开失败 文件不存在");
			return false;
		} 
		default: 
			alert("重开失败 其它错误:" + arr.result);
			return false;
		}
	}
	function shareFunction(arr) {
		switch (arr.result) {

		case "ok": {
			// arr.dire, arr.dird, arr.kcid, arr.fida, arr.hdst, arr.dlpt;
			// src = "dlpt/" + arr.dlpt;
			// alert("block:" + arr.bloc +" hdst:" + arr.hdst + "len:" +arr.assd.length + " AssignDisk:" + arr.assd);
			alert("分享成功");
		} break;
		case "file unexist": {
			alert("分享失败 文件不存在");
			return false;
		} 
		default: 
			alert("分享失败 其它错误:" + arr.result);
			return false;
		}
	}

</script>

</html>